//
//  LFBaseViewController.m
//  AntFarms
//
//  Created by LF on 2017/2/23.
//  Copyright © 2017年 GG. All rights reserved.
//

#import "LFBaseViewController.h"
#import "LFTabBar.h"

@interface LFBaseViewController ()

@end

@implementation LFBaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    self.view.backgroundColor = [UIColor backGroundGrayColor];
    
    [self setupBarItem];
    
    [self lf_addSubviews];
    [self lf_layoutNavigation];
    [self lf_bindViewModel];
    [self lf_getNewData];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    DismissHud();
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [LFTabBar sharedTabBar].display = self.isTopVc ? DisplayShow : DisplayHide;
    
//    [LFTabBar sharedTabBar].display = self.navigationController.viewControllers.count == 1 ? DisplayShow : DisplayHide;
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    if (self.isTopVc == NO) {
        [LFTabBar sharedTabBar].display = DisplayHide;
    }
}

/**
 使用VM配置初始化VC
 
 @param viewModel 对应的VM
 @return 对象
 */
- (instancetype)initWithViewModel:(id)viewModel {
    self = [super init];
    if (self) {
    }
    return self;
}

#pragma mark - RAC 四个常用的方法,写在LFViewControllerProtocol中
/**
 添加控件
 */
- (void)lf_addSubviews {}

/**
 绑定
 */
- (void)lf_bindViewModel {}

/**
 初次获取数据
 */
- (void)lf_getNewData {}

/**
 配置navigation,设置导航栏、分栏
 */
- (void)lf_layoutNavigation {
}


- (void) setupBarItem
{
    UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [leftButton setImage:[UIImage imageNamed:@"icon_arrow_left"] forState:0];
    leftButton.frame = CGRectMake(0, 0, 25, 25);
    leftButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    @weakify(self)
    [[leftButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        @strongify(self)
        [self.navigationController popViewControllerAnimated:YES];
    }];
    UIBarButtonItem *barItem = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
    self.navigationItem.leftBarButtonItem = barItem;

}

- (void)dealloc {
    NSLog(@"\n----销毁----\n----%@----dealloc \n", NSStringFromClass([self class]));
}

@end











